//封装方法

//wx.showToast设置为默认值
const toast = ({ title = '数据加载中...', icon = 'none', duration = 1000, mask = true } = {}) => {
  wx.showToast({
    title,
    icon,
    duration,
    mask
  })
}

//wx.modal封装
const modal = (options = {}) => {
  return new Promise((resolve) => {

    //默认参数
    const defaultOpt = {
      title: '提示',
      content: '你确定执行该操作吗?',
      confirmColor: '#f3514f'
    }

    //Object.assign参数合并
    //传入参数覆盖默认参数
    const opts = Object.assign({}, defaultOpt, options)

    wx.showModal({
      ...opts,
      complete: (res) => {
        if (res.cancel) {
              console.log(res);
        }

        if (res.confirm) {
          console.log(res);
        }
      }
    })
  })
}


wx.modal = modal

export { toast,modal }